package com.hc.appanimal;

import java.lang.reflect.Method;

import com.hc.DTO.AnimalCategoryMasterDTO;
import com.hc.DTO.AnimalDTO;
import com.hc.DTO.AnimalImagesDTO;
import com.hc.DTO.TokenDTO;
import com.hc.model.utils.AnimalModel;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

public class DetailAnimalActivity extends Activity implements OnClickListener {
	WebView wvDetail;
	Button btnMap, btnGallery, btnHome, btnDetail;
	AnimalDTO animalDTO;
	TextView txtTitle;
	Button btnBack;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail_animal);
		txtTitle = (TextView) findViewById(R.id.txtTitle);
		txtTitle.setTextSize(15.0f);
		btnBack = (Button) findViewById(R.id.btnBack);
		btnBack.setVisibility(View.VISIBLE);
		btnBack.setOnClickListener(this);
		Bundle data = getIntent().getExtras();
		if (data != null) {
			animalDTO = (AnimalDTO) data.getSerializable("images");
		}

		// AnimalModel model = AnimalModel.getInstance();
		// animalDTO = model.getAnimalById(this, dto.getId());
		wvDetail = (WebView) findViewById(R.id.wvDetail);

		btnMap = (Button) findViewById(R.id.btnMap);
		btnGallery = (Button) findViewById(R.id.btnGallery);
		btnMap.setOnClickListener(this);
		btnGallery.setOnClickListener(this);
		btnHome = (Button) findViewById(R.id.btnHome);
		btnHome.setOnClickListener(this);
		btnDetail = (Button) findViewById(R.id.btnDetail);
		btnDetail.setOnClickListener(this);
		// String CommonName = animalDTO.getCommonName();
		// if (CommonName.equalsIgnoreCase("null"))
		// CommonName = "";
		// String ScientificName = animalDTO.getScientificName();
		// if (ScientificName.equalsIgnoreCase("null"))
		// ScientificName = "";
		String SmallNote = animalDTO.getSmallNote();
		if (SmallNote.equalsIgnoreCase("null"))
			SmallNote = "";
		String MoreInfo = animalDTO.getMoreInfo();
		if (MoreInfo.equalsIgnoreCase("null"))
			MoreInfo = "";
		
		String tradeInfo = animalDTO.getTradeInfo();
		if (tradeInfo.equalsIgnoreCase("null"))
			tradeInfo = "";
		String TradeMapDesc = animalDTO.getTradeMapDesc();
		if (TradeMapDesc.equalsIgnoreCase("null"))
			TradeMapDesc = "";
		txtTitle.setText(animalDTO.getCommonName());
		// wvAbout.setBackgroundColor(0);
		// wvAbout.setBackgroundResource(Color.TRANSPARENT);
		// wvAbout.loadData(str, "text/html", "utf8");+ SmallNote + "<br>" 
		wvDetail.loadDataWithBaseURL(null,
				"<html><body background=\"#00000000\" link=\"white\"><font color=\"black\">"
						+ "<p text-align=\"right\">" + "<b>Details:</b>" + "<br>"
						+ MoreInfo + "<br>"+ "<br>" + "<b>Trade Details:</b><br>"
								+ tradeInfo + TradeMapDesc +"</p>"
						+ "</font></body</html>", "text/html", "UTF-8", null);
		wvDetail.setBackgroundColor(0x00000000);
		if (Build.VERSION.SDK_INT >= 11) // Android v3.0+
			try {
				Method method = View.class.getMethod("setLayerType", int.class,
						Paint.class);
				method.invoke(wvDetail, 1, new Paint()); // 1 =
															// LAYER_TYPE_SOFTWARE
															// (API11)
			} catch (Exception e) {
			}

		btnMap.setBackgroundResource(R.drawable.animal_map);
		btnGallery.setBackgroundResource(R.drawable.animal_images);
		btnDetail.setBackgroundResource(R.drawable.animal_detailsf);

	}

	@Override
	public void onClick(View v) {
		Intent intent;
		Bundle data = null;
		switch (v.getId()) {

		case R.id.btnMap:
			intent = new Intent(DetailAnimalActivity.this, MapActivity.class);
			data = new Bundle();
			data.putSerializable("images", animalDTO);
			intent.putExtras(data);
			startActivity(intent);
			finish();
			break;
		case R.id.btnGallery:
			intent = new Intent(DetailAnimalActivity.this,
					GalleryActivity.class);
			data = new Bundle();
			data.putSerializable("images", animalDTO);
			intent.putExtras(data);
			startActivity(intent);
			finish();
			break;
		case R.id.btnBack:
			finish();
			break;

		case R.id.btnHome:
			intent = new Intent(DetailAnimalActivity.this, SummaryActivity.class);
			data = new Bundle();
			data.putSerializable("images", animalDTO);
			intent.putExtras(data);
			startActivity(intent);
			finish();
			break;

		default:
			break;
		}

	}

}
